#include <stdarg.h>
#include <string.h>
#include <stdint.h>
#include <stdio.h>

// external symbols
extern void BspPutStr(const char* str, uint32_t len);

#define TX_BUF_LEN  256
char g_cliTxBuff[TX_BUF_LEN];
void LOG(const char *__format, ...)
{
    memset(g_cliTxBuff, 0x0, TX_BUF_LEN);
    va_list args;
    va_start(args, __format);
    vsprintf(g_cliTxBuff, __format, args);
    va_end(args);
    int len = strlen((const char*)g_cliTxBuff);

    BspPutStr(g_cliTxBuff, len);
}

/* to disable semi-hosting mode if needed */
/* necessary if using ac6 compiler */
int stderr_putchar(int c) { return 0; }
int stdin_getchar(void *ctx, size_t count, void *c) { return 0; }
int stdout_putchar(int c) { return 0; }

__asm(".global __use_no_semihosting");

void _sys_exit(int code) { 
    (void)code; 
    while(1);
}

void _ttywrch(int ch)
{
    (void)ch; 
    while(1);
}

char *_sys_command_string(char *cmd, int len) {
    (void)len;
    return cmd;
}